package com.jy.wms.common.quartz;

import com.jy.wms.service.WmsGoodsAlarmService;
import com.jy.wms.service.WmsReportsService;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;

@Configuration
public class SchedulerConfig {

    @Resource
    private WmsGoodsAlarmService ws;

    @Resource
    private WmsReportsService wmsReportsService;

    @Bean
    public SchedulerFactoryBean  getSchedulerFactoryBean() {
        return new SchedulerFactoryBean();
    }

    @Bean(name = "cronTrigger")
    public CronTrigger getTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 8 * * ?");
        return TriggerBuilder.newTrigger().withIdentity("wmsGoodsAlarmScheduledJobTrigger", "group1").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "jobDetail")
    public JobDetail getJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsGoodsAlarmService", ws);
        return JobBuilder.newJob(wmsGoodsAlarmScheduledJob.class).setJobData(jb).withIdentity("wmsGoodsAlarmScheduledJob", "group1").build();
    }

    @Bean(name = "StockcronTrigger")
    public CronTrigger getStockTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 23 L * ?");
        return TriggerBuilder.newTrigger().withIdentity("WmsReportsAlarmScheduledJobTrigger", "group2").withSchedule(scheduleBuilder).build();
    }

    @Bean(name = "StockjobDetail")
    public JobDetail getStockJobDetail() {
        JobDataMap jb = new JobDataMap();
        jb.put("wmsReportsService", wmsReportsService);
        return JobBuilder.newJob(WmsReportsAlarmScheduledJob.class).setJobData(jb).withIdentity("WmsReportsAlarmScheduledJob", "group2").build();
    }

}
